﻿using Architecture.API.Application.Command.UserInfoCommand;
using Architecture.Domain;
using Architecture.Domain.Service.UserInfoServices;
using MediatR;

namespace Architecture.API.Application.CommandHandlers.UserInfoHandler
{
    /// <summary>
    /// 用户信息更新命令处理器
    /// </summary>
    public class UserInfoUpdateCommandHandler : IRequestHandler<UserInfoUpdateCommand, int>
    {
        /// <summary>
        /// 用户信息服务
        /// </summary>
        private readonly IUserInfoService _userInfoService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="userInfoService">用户信息服务</param>
        public UserInfoUpdateCommandHandler(IUserInfoService userInfoService)
        {
            _userInfoService = userInfoService;
        }

        public async Task<int> Handle(UserInfoUpdateCommand request, CancellationToken cancellationToken)
        {
            return await _userInfoService.UpdateUserInfoAsync(new UserInfo() { UserId=request.UserId,UserName=request.UserName,UserPwd=request.UserPwd, Gender=request.Gender,ProvinceId=request.ProvinceId,CityId=request.CityId,CountyId=request.CountyId,Address=request.Address,DepartmentId=request.DepartmentId,CreatedBy=request.UserName,CreatedDate=DateTime.Now });
        }
    }
}
